package com.metacube.questionbank.dao;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.metacube.questionbank.dto.CommentDTO;

@Repository
public class CommentDAO {
	
	@Autowired
	DataSource dataSource;
	

	public int insertComment(CommentDTO commentDTO) {

	
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		String query = "insert into comment( QID, USERID, COMMENTDATE, COMMENTBODY)"
				+ " values(?,?,?,?)";
		System.out.println(commentDTO.getaId());
		return (jdbcTemplate.update(
				query,
				new Object[] { commentDTO.getqId(), 
						commentDTO.getUserId(), commentDTO.getCommentDate(),
						commentDTO.getCommentBody()}));
	}


	public int insertAnswerComment(CommentDTO commentDTO) {

		
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		String query = "insert into comment( AID, USERID, COMMENTDATE, COMMENTBODY)"
				+ " values(?,?,?,?)";
		System.out.println(commentDTO.getaId());
		return (jdbcTemplate.update(
				query,
				new Object[] { commentDTO.getaId(), 
						commentDTO.getUserId(), commentDTO.getCommentDate(),
						commentDTO.getCommentBody()}));
	}

}
